import cv2
import numpy as np

def additive_noise(image, sigma):
    h, w, c = image.shape
    noise = np.random.normal(0, sigma, (h, w, c))
    attacked_image = np.clip(image + noise, 0, 255).astype(np.uint8)
    return attacked_image

# 读取原始图像
image = cv2.imread("original_image.jpg")

# 添加加性高斯噪声攻击
sigma = 30  # 噪声强度
attacked_image = additive_noise(image, sigma)

# 显示原始图像和攻击后的图像
cv2.imshow("Original Image", image)
cv2.imshow("Attacked Image", attacked_image)
cv2.waitKey(0)
cv2.destroyAllWindows()